import { MyTrigger } from '../trigger/trigger'

export let MyAddressList = {
  tagName: 'u-address-list',
  template: '#' + 'address-list-tpl',
  components: {
    [MyTrigger.tagName]: MyTrigger
  },
  props: {
    items: {
      type: Array
    }
  },
  data() {
    return {
      data: this.getItems(),
      activeIndex: 0
    }
  },
  watch: {
    items(v) {
      this.data = this.getItems()
    }
  },
  methods: {
    getItems() {
      return this.items ? this.items : []
    },
    setActiveIndex(index) {
      this.activeIndex = index
    },
    onItemTaped(index) {
      this.setActiveIndex(index)
    },
    editAddress(item, index, data) {
      document.dispatchEvent(new CustomEvent('on-address-edit', {
        detail: {
          item, index, data
        }
      }))
    }
  }
}
